package com.sann.eduservice.controller;


import com.sann.common.utils.R;
import com.sann.eduservice.entity.chapter.Video;
import com.sann.eduservice.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频 前端控制器
 * </p>
 *
 * @author zjw
 * @since 2021-04-17
 */
@Api(tags = "视频管理")
@RestController
@RequestMapping("/eduservice/video")
@CrossOrigin
public class VideoController {

    @Autowired
    private VideoService videoService;

    @ApiOperation(value = "添加小节")
    @PostMapping(value = "save")
    public R save(@RequestBody Video video){
        try {
            boolean bol = this.videoService.save(video);
            if (bol) {
                return R.ok();
            }
            return R.error();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }

    @ApiOperation(value = "删除小节,同时把阿里云里面视频删除")
    @DeleteMapping(value = "deleteById/{videoId}")
    public R deleteById(@PathVariable String videoId){
        try {
            boolean bol = this.videoService.deleteVideoById(videoId);
            if (bol) {
                return R.ok();
            }
            return R.error();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error();
        }
    }

    // TODO 修改小节
    @ApiOperation(value = "修改小节", notes = "根据小节id进行修改")
    @PostMapping(value = "update")
    public R update(@RequestBody Video video){
        try {

            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }

    // TODO 根据ID查询小节
    @ApiOperation(value = "根据小节ID查询")
    @GetMapping(value = "getById/{videoId}")
    public R getById(@PathVariable String videoId){
        try {

            return R.ok();
        }catch (Exception e){
            e.printStackTrace();
            return R.error();
        }
    }


}

